package com.zhuhjay.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhuhjay.commonutils.R;
import com.zhuhjay.eduservice.entity.EduCourse;
import com.zhuhjay.eduservice.entity.EduTeacher;
import com.zhuhjay.eduservice.service.EduCourseService;
import com.zhuhjay.eduservice.service.EduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author ZhuHJay
 * @date 2022/9/8 19:51
 */
@Api(description = "前端讲师展示")
@RestController
@RequestMapping("/eduservice/teacherfront")

public class TeacherFrontController {

    @Resource
    private EduTeacherService teacherService;

    @Resource
    private EduCourseService courseService;

    @ApiOperation(value = "前端分页展示讲师列表")
    @PostMapping("getTeacherFrontList/{current}/{limit}")
    public R getTeacherFrontList(@PathVariable Long current, @PathVariable Long limit) {
        Page<EduTeacher> teacherPage = new Page<>(current, limit);
        teacherService.page(teacherPage, null);
        return R.ok()
                .data("items", teacherPage.getRecords())
                .data("current", teacherPage.getCurrent())
                .data("pages", teacherPage.getPages())
                .data("size", teacherPage.getSize())
                .data("total", teacherPage.getTotal())
                .data("hasNext", teacherPage.hasNext())
                .data("hasPrevious", teacherPage.hasPrevious());
    }

    @ApiOperation("讲师详情页功能")
    @GetMapping("getTeacherFrontInfo/{id}")
    public R getTeacherFrontInfo(@PathVariable String id) {
        // 讲师信息
        EduTeacher teacher = teacherService.getById(id);
        // 该讲师所讲的课程
        return R.ok().data("teacher", teacher)
                .data("courseList", courseService.list(new LambdaQueryWrapper<EduCourse>()
                                        .eq(EduCourse::getTeacherId, id)));
    }

}

